package com.york.aclservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.york.aclservice.service.IndexService;
import com.york.utils.exception.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Description:查询用户信息
 * @Data: 2022/3/30 13:28
 * @Author: yangboxiong
 * @Version
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/admin/acl/index")
public class IndexController {

    @Autowired
    private IndexService indexService;

    /**
     * 根据token获取用户信息
     *
     * @return
     */
    @GetMapping("/info")
    public R info() {
        //获取当前登录用户用户名
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        Map<String, Object> userInfo = indexService.getUserInfo(username);
        return R.ok().data(userInfo);
    }

    /**
     * 获取菜单
     *
     * @return
     */
    @GetMapping("/menu")
    public R getMenu() {
        //获取当前登录用户用户名
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        List<JSONObject> permissionList = indexService.getMenu(username);
        return R.ok().data("permissionList", permissionList);
    }

    /**
     * 退出
     *
     * @return
     */
    @PostMapping("/logout")
    public R logout() {
        return R.ok();
    }

}
